This page provides sample JSON text from a Dynamics CRM Online 2016 Service Endpoint plug-in. The JSON represents the execution context of an opportunity record that was closed as won (statuscode = 3). With this JSON instance, when sent to an Azure Service Bus queue, it's possible to use an Azure service such as a WebJob or Azure Function to parse the JSON and then send the entity details to another system (integration), call an Azure Logic App to use any of the available connectors to continue a workflow, etc.
This section contains sample code for checking various values in the JSON-based CRM execution context (as sent by the Service Endpoint) to determine whether your code (e.g., Azure Function or WebJob) should continue to process the message. Depending on the expected JSON message, there are other values to check, such as whether or not a particular field is present in the Target node and the value of the field.
See also:
{ "BusinessUnitId": "174df04e-3468-e611-80e0-c4346bb5980c", "CorrelationId": "7b0c3b09-b304-4388-b945-1d5248562f40", "Depth": 1, "InitiatingUserId": "f5478924-a0fe-461c-ab4f-f2380ada9227", "InputParameters": [ { "key": "Target", "value": { "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts", "Attributes": [ { "key": "opportunityid", "value": "80a2c641-4c79-e611-80df-c4346baca9e4" }, { "key": "statecode", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 1 } }, { "key": "statuscode", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 3 } }, { "key": "modifiedon", "value": "/Date(1473727936000)/" }, { "key": "modifiedby", "value": { "__type": "EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts", "Id": "f5478924-a0fe-461c-ab4f-f2380ada9227", "KeyAttributes": [], "LogicalName": "systemuser", "Name": null, "RowVersion": null } }, { "key": "modifiedonbehalfby", "value": null } ], "EntityState": null, "FormattedValues": [], "Id": "80a2c641-4c79-e611-80df-c4346baca9e4", "KeyAttributes": [], "LogicalName": "opportunity", "RelatedEntities": [], "RowVersion": null } } ], "IsExecutingOffline": false, "IsInTransaction": false, "IsOfflinePlayback": false, "IsolationMode": 1, "MessageName": "Update", "Mode": 1, "OperationCreatedOn": "/Date(1473727936000+0000)/", "OperationId": "b3f0f34f-4c79-e611-80df-c4346baca9e4", "OrganizationId": "95a4d234-d95c-432b-a871-d77f30291bd3", "OrganizationName": "altrivademo20160824", "OutputParameters": [], "OwningExtension": { "Id": "4d51a885-4b79-e611-80df-c4346bad4380", "KeyAttributes": [], "LogicalName": "sdkmessageprocessingstep", "Name": null, "RowVersion": null }, "ParentContext": { "BusinessUnitId": "174df04e-3468-e611-80e0-c4346bb5980c", "CorrelationId": "7b0c3b09-b304-4388-b945-1d5248562f40", "Depth": 1, "InitiatingUserId": "f5478924-a0fe-461c-ab4f-f2380ada9227", "InputParameters": [ { "key": "OpportunityClose", "value": { "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts", "Attributes": [ { "key": "opportunityid", "value": { "__type": "EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts", "Id": "80a2c641-4c79-e611-80df-c4346baca9e4", "KeyAttributes": [], "LogicalName": "opportunity", "Name": null, "RowVersion": null } }, { "key": "actualrevenue", "value": { "__type": "Money:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 0 } }, { "key": "description", "value": null }, { "key": "actualend", "value": "/Date(1473702861000+0000)/" } ], "EntityState": null, "FormattedValues": [], "Id": "00000000-0000-0000-0000-000000000000", "KeyAttributes": [], "LogicalName": "opportunityclose", "RelatedEntities": [], "RowVersion": null } }, { "key": "Status", "value": { "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", "Value": 3 } } ], "IsExecutingOffline": false, "IsInTransaction": false, "IsOfflinePlayback": false, "IsolationMode": 1, "MessageName": "Update", "Mode": 1, "OperationCreatedOn": "/Date(1473727936000+0000)/", "OperationId": "b3f0f34f-4c79-e611-80df-c4346baca9e4", "OrganizationId": "94a4d234-d95c-432b-a871-d77f30291bd3", "OrganizationName": "altrivademo20160824", "OutputParameters": [], "OwningExtension": { "Id": "4d51a885-4b79-e611-80df-c4346bad4380", "KeyAttributes": [], "LogicalName": "sdkmessageprocessingstep", "Name": null, "RowVersion": null }, "ParentContext": null, "PostEntityImages": [], "PreEntityImages": [], "PrimaryEntityId": "80a2c641-4c79-e611-80df-c4346baca9e4", "PrimaryEntityName": "opportunity", "RequestId": "242a8317-9e9d-4cba-a2a4-ec648080fcc0", "SecondaryEntityName": "none", "SharedVariables": [ { "key": "ChangedEntityTypes", "value": [ { "__type": "KeyValuePairOfstringstring:#System.Collections.Generic", "key": "opportunity", "value": "Update" } ] } ], "Stage": 30, "UserId": "f5478924-a0fe-461c-ab4f-f2380ada9227" }, "PostEntityImages": [ { "key": "AsynchronousStepPrimaryName", "value": { "Attributes": [ { "key": "name", "value": "Opportunity 1 Testing" }, { "key": "opportunityid", "value": "80a2c641-4c79-e611-80df-c4346baca9e4" } ], "EntityState": null, "FormattedValues": [], "Id": "80a2c641-4c79-e611-80df-c4346baca9e4", "KeyAttributes": [], "LogicalName": "opportunity", "RelatedEntities": [], "RowVersion": null } } ], "PreEntityImages": [], "PrimaryEntityId": "80a2c641-4c79-e611-80df-c4346baca9e4", "PrimaryEntityName": "opportunity", "RequestId": "242a8317-9e9d-4cba-a2a4-ec648080fcc0", "SecondaryEntityName": "none", "SharedVariables": [], "Stage": 40, "UserId": "f5478924-a0fe-461c-ab4f-f2380ada9227" }Parsing the JSON Execution Context
This section contains sample code for checking various values in the JSON-based CRM execution context (as sent by the Service Endpoint) to determine whether your code (e.g., Azure Function or WebJob) should continue to process the message. Depending on the expected JSON message, there are other values to check, such as whether or not a particular field is present in the Target node and the value of the field.private bool IsExecutionContextForUpdateOfOpportunity(string jsonText) { JObject jsonObj = JObject.Parse(jsonText); bool isValid = false; string EC_ElementName_InputParameters = "InputParameters"; string EC_ElementName_Target = "Target"; string EC_ElementName_MessageName = "MessageName"; string EC_ElementName_PrimaryEntityName = "PrimaryEntityName"; string OpportunityEntityLogicalName = "opportunity"; if (jsonObj[EC_ElementName_InputParameters] != null && jsonObj[EC_ElementName_InputParameters][0]["key"].ToString() == EC_ElementName_Target && jsonObj[EC_ElementName_MessageName] != null && jsonObj[EC_ElementName_MessageName].ToString() == "Update" && jsonObj[EC_ElementName_PrimaryEntityName].ToString() == OpportunityEntityLogicalName) { isValid = true; } return isValid; }.
Related Tools
Beautify JSONjson2csharp - generate c# classes from json
.